package com.zhangzhan.controller;

import com.zhangzhan.domain.commcon.ResponseResult;
import com.zhangzhan.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张一恒
 * @version 1.0
 */
//文章controller层
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    //@GetMapping("/list")
    //public List<Article> test(){
    //   return articleService.list();
    //}

    /**
     * 热门文章的查询
     */
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticle(){
        return articleService.hotArticle();
    }

    /**
     * 文章分页查询
     * 带参数
     * @return
     */
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,
                                      Integer pageSize,
                                      Long categoryId){
        //调用业务逻辑层实现代码书写
      return  articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**
     * 展示文章详情
     */
    @GetMapping("/{id}")
    public ResponseResult selectById(@PathVariable Long id){
       return articleService.selectById(id);
    }


    /**
     * @description 更新文章浏览量
     * @param id
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/4 21:53
     */
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable Long id){
        return articleService.updateViewCount(id);
    }
}
